///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.basecamp.wrappers
{
import summit.basecamp.constants.BasecampResource;
import summit.basecamp.helpers.PersonHelper;
import summit.data.AccountToken;
import summit.net.BasecampLoader;

/**
 * Wrapper for Basecamp person operations.
 */
public class PersonWrapper extends AbstractWrapper implements
IChildWrapper
{
	/** Constructor.
	 * @param token The <code>AccountToken</code> that is to be used in 
	 * identifying the Basecamp account to which make API calls are made.
	 * @param loader The <code>BasecampLoader</code> that is to be used 
	 * with all requested operations.
	 */
	public function PersonWrapper(token:AccountToken = null, 
	loader:BasecampLoader = null)
	{
		super(BasecampResource.PERSON, token, loader);
	}
	
	/** Gets a new instance of a <code>CompanyWrapper</code>. **/
	public function get parent():IParentWrapper
	{
		return new CompanyWrapper(null, loader);
	}
	
	/**
	 * Reads a single person.
	 * 
	 * <p>Providing a <code>null</code> <code>id</code> will return the person
	 * for the requesting user, represented by the <code>AccountToken</code> 
	 * passed to the loader.</p>
	 * 
	 * @param id The id of the person to be read.
	 * 
	 * @return A request ready for use with <code>BasecampLoader.load</code>.
	 */
	public function read(id:String):void
	{
		loader.load(PersonHelper.read(id));
	}
	
	/** Gets a list of all people associated with a specified company with 
	 * access to a specified project.
	 * 
	 * @param companyId
	 * The id of a company.  
	 * @param projectId
	 * The id of a project. 
	 **/
	public function list(companyId:String, projectId:String):void
	{
		loader.load(PersonHelper.list(companyId, projectId));
	}
	
	/** Gets a list of all people for a specified project.
	 * 
	 * @param projectId
	 * The id of the project used to scope the list. **/
	public function listByProject(projectId:String):void
	{
		loader.load(PersonHelper.list(null, projectId));
	}
	
	/** Gets a list of all people for a specified company.
	 * 
	 * @param companyId
	 * The id of the company used to scope the list. **/
	public function listByCompany(companyId:String):void
	{
		loader.load(PersonHelper.list(companyId, null));
	}
	
	/** Gets a list of all people across all companies and projects. **/
	public function listAll():void
	{
		loader.load(PersonHelper.list(null, null));
	}
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //